﻿// -------------------------------------------------------------------------
//    @FileName         :    NFSnsPart.cpp
//    @Author           :    gaoyi
//    @Date             :    24-8-30
//    @Email            :    445267987@qq.com
//    @Module           :    NFSnsPart
//
// -------------------------------------------------------------------------

#include "NFSnsPart.h"

#include "proto_cs_login.pb.h"
#include "proto_db.pb.h"

NFSnsPart::NFSnsPart()
{
    if (EN_OBJ_MODE_INIT == NFShmMgr::Instance()->GetCreateMode()) { CreateInit(); }
    else { ResumeInit(); }
}

NFSnsPart::~NFSnsPart()
{
}

int NFSnsPart::CreateInit() { return 0; }

int NFSnsPart::ResumeInit() { return 0; }

int NFSnsPart::LoadFromDB(const proto_ff::tbRoleDetail* pDBData)
{
    m_stData.FromPb(pDBData->role_other_data().sns());
    return 0;
}

int NFSnsPart::InitConfig(proto_ff::tbRoleDetail* pDbData, const RoleOne& stRoleOne)
{
    CHECK_NULL(0, pDbData);
    auto pData = pDbData->mutable_role_other_data()->mutable_sns();
    pData->mutable_corps_data()->set_floor(1);
    pData->mutable_corps_data()->set_history_max_floor(1);
    pData->mutable_family_data()->set_uuid(0);
    pData->mutable_guild_role()->mutable_guild_question()->set_question_index(0);
    pData->set_day_refresh_time(NF_ADJUST_TIMENOW());
    for (int i = proto_ff::EN_ARCHI_SHOP; i <= proto_ff::EN_ARCHI_MAIN; ++i) { pData->mutable_guild_role()->mutable_guild_base_info()->add_arc_info()->set_archi_lv(0); }

    return 0;
}

int NFSnsPart::SaveDB(proto_ff::tbRoleDetail* pDBData)
{
    m_stData.ToPb(pDBData->mutable_role_other_data()->mutable_sns());
    return 0;
}

int NFSnsPart::SaveRoleSimpleInfo(proto_ff::Proto_RoleSimpleInfo* pDbData)
{
    CHECK_NULL(0, pDbData);
    pDbData->set_guild_id(GetGuildID());
    pDbData->set_guild_title((proto_ff::enGuildMemTitle)GetGuildTitle());
    pDbData->set_guild_name(GetGuildName());
    pDbData->set_battle_corps_id(m_stData.corps_data.id);
    return 0;
}

int NFSnsPart::MakePlayerDataCS(proto_ff::Proto_CSGetRoleRsp* pCSGetRoleRsp)
{
    m_stData.ToPb(pCSGetRoleRsp->mutable_sns_data());
    return 0;
}

int NFSnsPart::MakeCityPlayerData(proto_ff::CityRoleInfo* pGCCityRoleInfo)
{
    CHECK_NULL(0, pGCCityRoleInfo);
    pGCCityRoleInfo->set_guild_id(GetGuildID());
    return 0;
}

void NFSnsPart::SetGuildQuestionIndex(int index)
{
    m_stData.guild_role.guild_question.question_index = index;
    MarkDirty();
}

void NFSnsPart::AddGuildWeekContribute(int num)
{
    if (num > 0)
    {
        m_stData.guild_role.guild_contri.week_contri += num;
        MarkDirty();
    }
}

void NFSnsPart::AddGuildWeekBonus(int num)
{
    if (num > 0)
    {
        m_stData.guild_role.guild_bonus_info.week_bonus += num;
        MarkDirty();
    }
}
